package cn.breeze.basic.controller;

import cn.breeze.basic.exception.BusinessException;
import cn.breeze.basic.utils.AjaxResult;
import cn.breeze.basic.vo.RegisterVo;
import cn.breeze.basic.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* @Title:
* @Description: 验证码接口类
* @Author: Mr.D
* @Version: 1.0
* @Date:  2022/7/4 16:08
* @Parameters:
* @Return
*/
@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    /**
    * @Title: auditPass
    * @Description: 获取图形验证码
    * @Author: Mr.D
    * @Version: 1.0
    * @Date:  2022/7/4 16:09
    * @Parameters: [shopAuditLog]
    * @Return cn.breeze.basic.utils.AjaxResult
    */
    @GetMapping("/image/{verifyCodeKey}")
    public AjaxResult graphics(@PathVariable("verifyCodeKey")String verifyCodeKey)
    {
        try {
            String imgBase64Str = iVerifyCodeService.graphicsBase64Str(verifyCodeKey);
            return AjaxResult.me().setResultObj(imgBase64Str);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试");
        }
    }

    /**
    * @Title: graphics
    * @Description: 发送手机验证码
    * @Author: Mr.D
    * @Version: 1.0
    * @Date:  2022/7/5 22:51
    * @Parameters: [verifyCodeKey]
    * @Return cn.breeze.basic.utils.AjaxResult
    */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody RegisterVo registerVo)
    {
        try {
            iVerifyCodeService.smsCode(registerVo);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试");
        }
    }

    /**
    * @Title: emailCode
    * @Description: 发送邮箱验证码
    * @Author: Mr.D
    * @Version: 1.0
    * @Date:  2022/7/6 16:25
    * @Parameters: [registerVo]
    * @Return cn.breeze.basic.utils.AjaxResult
    */
    @PostMapping("/emailCode")
    public AjaxResult emailCode(@RequestBody RegisterVo registerVo)
    {
        try {
            iVerifyCodeService.emailCode(registerVo);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试");
        }
    }
}
